home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.mactech.com 2010
/
ftp.mactech.com.tar
/
ftp.mactech.com
/
macintosh-c
/
macc-carbon-demos-nonbinhex.sit
/
macc-carbon-demos-nonbinhex
/
chap18-demo-carbon events
/
Files.h
< prev
next >
Wrap
Text File
|
2001-06-11
|
8KB
|
177 lines
// *******************************************************************************************
// Files.h CARBON EVENT MODEL
// *******************************************************************************************
//
// This program demonstrates:
//
// • File operations associated with:
//
// • The user invoking the Open…, Close, Save, Save As…, Revert, and Quit commands of a
// typical application.
//
// • Handling of the required Apple events Open Application, Re-open Application, Open
// Documents, Print Documents, and Quit Application.
//
// • File synchronisation.
//
// • The creation, display, and handling of Open, Save Location, Choose a Folder, Save
// Changes, Discard Changes, and Review Unsaved dialogs and alerts using the new model
// introduced with Navigation Services 3.0.
//
// To keep the code not specifically related to files and file-handling to a minimum, an item
// is included in the Demonstration menu which allows the user to simulate "touching" a window
// (that is, modifying the contents of the associated document). Choosing the first menu item
// in this menu sets the window-touched flag in the window's document structure to true and
// draws the text "WINDOW TOUCHED" in the window in a large font size, this latter so that the
// user can keep track of which windows have been "touched".
//
// This program is also, in part, an extension of the demonstration program Windows2 in that
// it also demonstrates certain file-related Window Manager features introduced with the Mac
// OS 8.5 Window Manager. These features are:
//
// • Window proxy icons.
//
// • Window path pop-up menus.
//
// Those sections of the source code relating to these features are identified with ///// at
// the right of each line.
//
// The program utilises the following resources:
//
// • A 'plst' resource containing an information property list which provides information
// to the Mac OS X Finder.
//
// • An 'MBAR' resource, and 'MENU' and 'xmnu' resources for Apple, File, Edit and
// Demonstration menus (preload, non-purgeable).
//
// • A 'STR ' resource containing the "missing application name" string, which is copied to
// all document files created by the program.
//
// • 'STR#' resources (purgeable) containing error strings, the application's name (for
// certain Navigation Services functions), and a message string for the Choose a Folder
// dialog.
//
// • An 'open' resource (purgeable) containing the file type list for the Open dialog.
//
// • A 'kind' resource (purgeable) describing file types, which is used by Navigation
// Services to build the native file types section of the Show pop-up menu in the Open
// dialog.
//
// • Two 'pnot' resources (purgeable) which, together with an associated 'PICT' resource
// (purgeable) and a 'TEXT' resource created by the program, provide the previews for
// the PICT and, on Mac OS 8/9, TEXT files.
//
// • The 'BNDL' resource (non-purgeable), 'FREF' resources (non-purgeable), signature
// resource (non-purgeable), and icon family resources (purgeable), required to support the
// built application on Mac OS 8/9.
//
// • A 'SIZE' resource with the acceptSuspendResumeEvents, canBackground,
// doesActivateOnFGSwitch, and isHighLevelEventAware flags set.
//
// *******************************************************************************************
// ………………………………………………………………………………………………………………………………………………………………………………………………………………………… includes
#include <Carbon.h>
// …………………………………………………………………………………………………………………………………………………………………………………………………………………………… defines
#define rMenubar 128
#define mAppleApplication 128
#define Apple_About 'abou'
#define mFile 129
#define File_New 'new '
#define File_Open 'open'
#define File_Close 'clos'
#define File_Save 'save'
#define File_SaveAs 'sava'
#define File_Revert 'reve'
#define File_Quit 'quit'
#define iQuit 12
#define mDemonstration 131
#define Demo_TouchWindow 'touc'
#define Demo_ChooseAFolderDialog 'choo'
#define rErrorStrings 128
#define eInstallHandler 1000
#define eMaxWindows 1001
#define eCantFindFinderProcess 1002 /////
#define rMiscStrings 129
#define sApplicationName 1
#define sChooseAFolder 2
#define rOpenResource 128
#define kMaxWindows 10
#define kFileCreator 'Kjbb'
#define kFileTypeTEXT 'TEXT'
#define kFileTypePICT 'PICT'
#define kOpen 0
#define kPrint 1
#define MIN(a,b) ((a) < (b) ? (a) : (b))
// ………………………………………………………………………………………………………………………………………………………………………………………………………………………… typedefs
typedef struct
{
TEHandle editStrucHdl;
PicHandle pictureHdl;
SInt16 fileRefNum;
FSSpec fileFSSpec;
AliasHandle aliasHdl;
Boolean windowTouched;
NavDialogRef modalToWindowNavDialogRef;
NavEventUPP askSaveDiscardEventFunctionUPP;
Boolean isAskSaveChangesDialog;
} docStructure, *docStructurePointer, **docStructureHandle;
// …………………………………………………………………………………………………………………………………………………………………………………………… function prototypes
void main (void);
void eventLoop (void);
void doPreliminaries (void);
void doInstallAEHandlers (void);
OSStatus appEventHandler (EventHandlerCallRef,EventRef,void *);
OSStatus windowEventHandler (EventHandlerCallRef,EventRef,void *);
void doIdle (void);
void doDrawContent (WindowRef);
void doMenuChoice (MenuCommand);
void doAdjustMenus (void);
void doErrorAlert (SInt16);
void doCopyPString (Str255,Str255);
void doConcatPStrings (Str255,Str255);
void doTouchWindow (void);
OSErr openAppEventHandler (AppleEvent *,AppleEvent *,SInt32);
OSErr reopenAppEventHandler (AppleEvent *,AppleEvent *,SInt32);
OSErr openAndPrintDocsEventHandler (AppleEvent *,AppleEvent *,SInt32);
OSErr quitAppEventHandler (AppleEvent *,AppleEvent *,SInt32);
OSErr doHasGotRequiredParams (AppleEvent *);
SInt16 doReviewChangesAlert (SInt16);
OSErr doNewCommand (void);
OSErr doOpenCommand (void);
OSErr doCloseCommand (NavAskSaveChangesAction);
OSErr doSaveCommand (void);
OSErr doSaveAsCommand (void);
OSErr doRevertCommand (void);
OSErr doNewDocWindow (Boolean,OSType,WindowRef *);
EventHandlerUPP doGetHandlerUPP (void);
OSErr doCloseDocWindow (WindowRef);
OSErr doOpenFile (FSSpec,OSType);
OSErr doReadTextFile (WindowRef);
OSErr doReadPictFile (WindowRef);
OSErr doCreateAskSaveChangesDialog (WindowRef,docStructureHandle,NavAskSaveChangesAction);
OSErr doSaveUsingFSSpec (WindowRef,NavReplyRecord *);
OSErr doSaveUsingFSRef (WindowRef,NavReplyRecord *);
OSErr doWriteFile (WindowRef);
OSErr doWriteTextData (WindowRef,SInt16);
OSErr doWritePictData (WindowRef,SInt16);
void getFilePutFileEventFunction (NavEventCallbackMessage,NavCBRecPtr,NavCallBackUserData);
void askSaveDiscardEventFunction (NavEventCallbackMessage,NavCBRecPtr,NavCallBackUserData);
OSErr doCopyResources (WindowRef);
OSErr doCopyAResource (ResType,SInt16,SInt16,SInt16);
void doSynchroniseFiles (void);
OSErr doChooseAFolderDialog (void);
// *******************************************************************************************